import json

from ronglian_sms_sdk import SmsSDK

# from flask import current_app


class SendSms(object):
    _instance = None

    def __new__(cls, *args, **kwargs):
        if cls._instance is None:
            cls._instance = super().__new__(cls, *args, **kwargs)
            from app.main import app

            accId = app.config['ACCID']
            accToken = app.config['ACCTOKEN']
            appId = app.config['APPID']
            print(accId,accToken,appId)

            print("------------------------------------")
            cls._instance.sms_sdk = SmsSDK(accId,accToken, appId)

        return cls._instance

    def send_message(self, mobile='17627916221', datas=("666666", "3"), tid="1"):
        resp = self.sms_sdk.sendMessage(tid, mobile, datas)

        ret = json.loads(resp)

        if ret["statusCode"] == "000000":
            return 1
        else:
            return 0

if __name__ == '__main__':

    send_sms = SendSms()
    print(send_sms.send_message())